#include <iostream>
using namespace std;

int main()
{
  int best = 0;
  int longest = 0;
  for(int i = 1; i < 1000000; i++)
  {
    unsigned int current = i;
    int length = 0;
    while(current != 1)
    {
      if(current % 2 == 0)
      {
        current /= 2;
      }
      else
      {
        current = (current * 3) + 1;
      }
      length++;
    }
    if(length > longest)
    {
      best = i;
      longest = length;
    }
  }
  cout << "The longest chain starts with: " << best;
  return 0;
}
